// pages/wode/bill.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    lists:[],
    page:1,
    limit:10,
    empty:false,
    isLoadingAll:false,
    keywords:'',
    type:1,
    countData:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getData()
    this.getList()
  },

  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.setData({
      lists:[],
      page:1,
      limit:10,
      empty:false,
      isLoadingAll:false,
    })
    this.getList()

    wx.stopPullDownRefresh()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if(!this.data.isLoadingAll){
      this.data.page++
      this.getList()
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  tab:function(e){
    var that=this
    var type=e.currentTarget.dataset.type

    that.setData({
      type:type,
      lists:[],
      page:1,
      empty:false,
      isLoadingAll:false,
      keywords:''
    })
    this.getList()
    
  },

  getData:function(){
    var that=this
    var userInfo=wx.getStorageSync('userInfo')
    var data={}
    data.id=userInfo.storeId
    app.agriknow.commRequest('ht/store/incomeTopData',data).then(res=>{
      console.log(res)
      var datas=res.data
      datas.dayPrice=datas.dayPrice.toFixed(2)
      datas.weekPrice=datas.weekPrice.toFixed(2)
      datas.mouthPrice=datas.mouthPrice.toFixed(2)
      that.setData({
        countData:datas
      })
     
   })

  },

  getList:function(){
    var that=this
    var userInfo=wx.getStorageSync('userInfo')
    var data={}
    data.id=userInfo.storeId
    data.page=this.data.page
    data.limit=this.data.limit
    data.type=this.data.type
    if(this.data.keywords){
      data.keywords=this.data.keywords
    }
   // data.storeId=wx.getStorageSync('userInfo').storeId
    app.getList('ht/store/incomePage',data,that)
  },
  submit:function(e){
    console.log(e)
    var datas=e.detail.value
    if(!datas.keywords){
        wx.showToast({
          title: '订单编号不能为空',
          icon:'none',
          duration:1500,
          mask:true
        })
        return false
    }
    this.setData({
      lists:[],
      page:1,
      empty:false,
      isLoadingAll:false,
      keywords:datas.keywords,
      type:1
    })
    this.getList()

  },

  toDetail:function(e){
    var id=e.currentTarget.dataset.id
    var type=e.currentTarget.dataset.type
    wx.navigateTo({
      url: '/pages/orderDetail/index?id='+id+'&type='+type,
    })
  }
})